
$(document).ready(function () {

    // MODAL WINDOW
    $('.modalopen').each(function () {
        $.data(this, 'dialog',
		  $('.modal').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 700,
		      height: 392
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });
    // MODAL WINDOW For CONFIRM DELETE

    $('.modalopenConfirmDel').each(function () {
        $.data(this, 'dialog',
		$('.modalConfirmDelete').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 400,
		    height: 140
		}));
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    $('.modalopenInstructionDiv').each(function () {
        $.data(this, 'dialog',
		$('.modalInstructionDiv').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 500,
		    height: 140
		}));
    });

    $('.modalopenTooltip').each(function () {
        $.data(this, 'dialog',
		$('.modalTooltip').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: false,
		    show: "fade",
		    hide: "fade",
		    width: 400,
		    height: 140
		}));
    });
    // Model for general address 
    $('.modalopen800by600').each(function () {
        $.data(this, 'dialog',
		$('.modal800by600').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 800,
		    height: 600
		}));
    });
    $('.modalopen850by600').each(function () {
        $.data(this, 'dialog',
		$('.modal850by600').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 850,
		    height: 600
		}));
    });
    $('.modalopen1024by600').each(function () {
        $.data(this, 'dialog',
		$('.modalopen1024by600').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 1024,
		    height: 600
		}));
    });
    $('.modalopen950by600').each(function () {
        $.data(this, 'dialog',
		$('.modal950by600').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 950,
		    height: 600
		}));
    });
    $('.modalopen950by700').each(function () {
        $.data(this, 'dialog',
		$('.modal950by700').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 950,
		    height: 700
		}));
    });
    $('.modalopen850by480').each(function () {
        $.data(this, 'dialog',
		$('.modal850by480').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 850,
		    height: 480
		}));
    });
    $('.modalopen850by650').each(function () {
        $.data(this, 'dialog',
		$('.modal850by650').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 850,
		    height: 750
		}));
    });
    $('.modalopen550by600').each(function () {
        $.data(this, 'dialog',
		$('.modal550by600').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 550,
		    height: 600
		}));
    });
    $('.modalopen550by650').each(function () {
        $.data(this, 'dialog',
		$('.modal550by650').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 550,
		    height: 700
		}));
    });
    $('.modalopenInsertEdit').each(function () {
        $.data(this, 'dialog',
		  $('.modalInsertEdit').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 350,
		      height: 400
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    $('.modalopenDownloadDiv').each(function () {
        $.data(this, 'dialog',
		  $('.modalDownloadDiv').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 500,
		      height: 330
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    $('.modalopenCommentShowDiv').each(function () {
        $.data(this, 'dialog',
		  $('.modalCommentShowDiv').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 550,
		      height: 200
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    $('.modalopen550by100').each(function () {
        $.data(this, 'dialog',
		  $('.modal550by100').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 550,
		      height: 100
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });


    $('.modalopenChangePassword').each(function () {
        $.data(this, 'dialog',
		  $('.modalChangePassword').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 370,
		      height: 315
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    $('.modalopen450by800').each(function () {
        $.data(this, 'dialog',
		  $('.modal450by800').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 550,
		      height: 650
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    //Modal for User 
    $('.modalopenCompany').each(function () {
        $.data(this, 'dialog',
		  $('.modalCompany').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 800,
		      height: 600
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    //Modal for User 
    $('.modalopenContract').each(function () {
        $.data(this, 'dialog',
		  $('.modalContract').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 800,
		      height: 320
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    //Modal for User 
    $('.modalopenFinancialYear').each(function () {
        $.data(this, 'dialog',
		  $('.modalFinancialYear').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 800,
		      height: 250
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    //Modal for User 
    $('.modalopenServiceTaxDet').each(function () {
        $.data(this, 'dialog',
		  $('.modalServiceTaxDet').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 800,
		      height: 280
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });


    //Modal for User 
    $('.modalopenUser').each(function () {
        $.data(this, 'dialog',
		  $('.modalUser').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 400,
		      height: 480
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    //Modal for User 
    $('.modalopenPaymentMode').each(function () {
        $.data(this, 'dialog',
		  $('.modalPaymentMode').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 400,
		      height: 480
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    $('.modalopenPaymentLevel').each(function () {
        $.data(this, 'dialog',
		  $('.modalPaymentLevel').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 800,
		      height: 350
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });

    $('.modalopenInvoice').each(function () {
        $.data(this, 'dialog',
		  $('.modalinvoice').dialog({
		      autoOpen: false,
		      closeText: '',
		      resizable: false,
		      modal: true,
		      show: "fade",
		      hide: "fade",
		      width: 800,
		      height: 500
		  })
		);
    }).click(function () {
        $.data(this, 'dialog').dialog('open');
        return false;
    });


    $('.modalopen1000by500').each(function () {
        $.data(this, 'dialog',
		$('.modal1000by500').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 1000,
		    height: 500
		}));
    });

    $('.modalopen650by200').each(function () {
        $.data(this, 'dialog',
		$('.modal650by200').dialog({
		    autoOpen: false,
		    closeText: '',
		    resizable: false,
		    modal: true,
		    show: "fade",
		    hide: "fade",
		    width: 700,
		    height: 180
		}));
    });

    // DATATABLE
    table_all();
    table_pagesort();
    table_sortsearch();
    table_sorting();
    table_simple();
    fn_DatePicker();

    if (document.getElementById('divTopContainer') == null)
        $('.rightcontainer').css("margin-top", "0");

    $('.ui-dialog-titlebar-close').attr("title", "Close");

    $(".modal-date").focus(function () {
        $(".datepicker").css('z-index', '10000');
    });

    $('.ui-dialog-titlebar-close').bind('keyup', function (e) {
        if (e.which == 13)
            $('#divDeleteConfirmation').dialog('close');
    });

    //    if ($('.dateinput') != null || $('.dateinput') != undefined) {
    //        $('.dateinput').datepicker('update', '');
    //        $('.dateinput').val("");
    //    }
});

function fn_DatePicker() {
    $(".dateinput").datepicker({
        autoOpen: false,
        showOn: "button",
        format: 'dd/mm/yyyy',
        regional: 'en-GB',
        startDate: null,
        endDate: null
    });
}

function table_all() {
    $('table.all').dataTable({
        "bInfo": true,
        "iDisplayLength": 25,
        "aLengthMenu": [[5, 10, 25, 50, 100], [5, 10, 25, 50, 100]],
        "sPaginationType": "full_numbers",
        "bPaginate": true,
        "sDom": '<"top"i>rt<"bottom"flp><"clear">',
        "bRetrieve": true,
        "aoColumnDefs": [{ "bSortable": false, "aTargets": [0] }]
    });
}

function table_pagesort() {
    $('table.pagesort').dataTable({
        "bInfo": false,
        "iDisplayLength": 10,
        "aLengthMenu": [[5, 10, 25, 50, 100], [5, 10, 25, 50, 100]],
        "sPaginationType": "full_numbers",
        "bPaginate": true,
        "bFilter": false,
        "sDom": 't<pl>'
    });
}

function table_sortsearch() {
    $('table.sortsearch').dataTable({
        "bInfo": false,
        "bPaginate": false,
        "sDom": 't<plf>'
    });
}

function table_sorting() {
    $('table.sorting').dataTable({
        "bInfo": false,
        "bPaginate": false,
        "bFilter": false,
        "sDom": 't<plf>'
    });
}

function table_simple() {
    $('table.simple').dataTable({
        "bInfo": false,
        "bPaginate": false,
        "bSort": false,
        "bFilter": false,
        "bAutoWidth": false,
        "bRetrieve": true,
        "sDom": '<"top"i>rt<"bottom"flp><"clear">'
    });
}

function toggle_LeftContainer() {
    var leftWidth = $('#searchBox').width();
    if (leftWidth == 0) {
        $('#searchBox').css("width", "250px");
        $('#searchBox').show();
        $('#dataBox').css("margin-left", "270px");
    }
    else {
        $('#searchBox').css("width", "0");
        $('#searchBox').hide();
        $('#dataBox').css("margin-left", "15px");
    }
}

function toggle_TopContainer() {
    var vDivHeight = $('#divTopContainer').height();
    if (vDivHeight == 0) {
        $('#divTopContainer').css("height", "20%");
        $('#divTopContainer').show();
        //if ($('.listdiv')[0] != undefined) {
        //    $('.listdiv').css("height", (500 - parseInt($('#divTopContainer').height())) + "px");
        //    var vDivID = $('.listdiv')[0].id;
        //    document.getElementById(vDivID).childNodes[1].style.height = (480 - parseInt($('#divTopContainer').height())) + "px";
        //}
    }
    else {
        $('#divTopContainer').css("height", "0");
        $('#divTopContainer').hide();
        //if ($('.listdiv')[0] != undefined) {
        //    //$('.listdiv').css("height", "500px");
        //    //var vDivID = $('.listdiv')[0].id;
        //    //document.getElementById(vDivID).childNodes[1].style.height = "480px";
        //}
    }
}
